<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03.解构赋值</title>
</head>
<body>

    <script>
        /*
          解构赋值：将变量拿出来获取其中的值
            三种： 数组的解构: 对应的是索引
                  对象的解构： 对应的是对象的key
        */
        // 定义多个变量  多变量定义赋值
        let a=10,b=20,c=30;
        console.log(a,b,c);
        // 定义多变量就是一个数组
        let [a1,b1,c1] = [10,20,30]
        console.log(a1,b1,c1);
        
        let [a2,b2,c2] = [10,,30,40]
        console.log(a2,b2,c2);

        // 多维数组的赋值
        let [js,[nj,[qh,yh],wx,[nc,bh]]] = ["江苏省",["南京市",["秦淮区","雨花区"],"无锡市",["南长区","滨湖区"]]]
        console.log(js,nj,qh,yh,wx,nc,bh);

        // 对象的解构
        const stu = {
            name:"小明",
            age:18,
            friend:{
                name:"小红",
                age:20,
                cars:["奔驰","奥迪"]
            }
        }
        // const {name,age} = stu
        // console.log(name,age);

        const {name:n,age,friend:{name:xh,age:xhage,cars:[bc,bm]}} = stu
        // console.log(name,age,friend);
        console.log(n,age,xh,xhage,bc,bm);


        console.dir([1,2,3]);
        console.dir(new String("123"));
        const str = new String("123");
        const [a4,b4,c4] = str;
        console.log(a4,b4,c4);
        console.log("解构赋值的应用。。。。。。。。。。。");

        // function fun(name,age,address) {
        //     console.log(name,age,address);

        // }

        function fun({name,age,address}) {
            console.log(name,age,address);

        }
        // fun("小明",18,"无锡市")
        const person = {
           name:"小明",
           age:18,
           address:"无锡市"
        }

        fun(person)
    </script>
    
</body>
</html>